<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>location</title>
</head>
<script type="text/javascript">

    window.onload = function () {
        var btn = document.getElementById('btn');
        btn.onclick = function(){

            location = 'https://www.baidu.com/';

            console.log(location);

            alert(location);
        };

    }

</script>
<body>
<button id='btn'>点击我</button>
</body>
</html>